package uia.alumni.data;

/**
 * To follow relation DB this is done through a
 * extra table called group_participation. Each group will also have a
 * admin. This is done with roles. So we reuse the roles enum class in this
 * Context.
 *
 * v1 Thu Oct 29.
 *
 * @Author: Simon Zimmermann.
 */


import javax.persistence.*;

@Entity
@Table(name="is202_alumni_group_participation")
@NamedQuery(name="GroupParticipation.selectAll",query="select gp from GroupParticipation gp")
@IdClass(GroupParticipationId.class)
public class GroupParticipation {

    // Declaring variables, column names and mapping.
    @Column(name = "member_role")
    private Role memberRole;

    @Id
    @Column(name = "group_id", insertable=false, updatable=false)
    private long groupId;

    @Id
    @Column(name = "user_id", insertable=false, updatable=false)
    private long userId;

    @ManyToOne
    @JoinColumn(name = "user_id", referencedColumnName="user_id")
    private User user;

    @ManyToOne
    @JoinColumn(name = "group_id", referencedColumnName="group_id")
    private Group group;

    // Constructors.
    public GroupParticipation(){}

    /**
     * Constructor for the Group Participation.
     * @param user
     * @param group
     * @param memberRole
     */
    public GroupParticipation(User user, Group group, Role memberRole){
       this.user = user;
       this.userId = getUserId();
       this.group = group;
       this.groupId = getGroupId();
       this.memberRole = memberRole;
    }

    // Getters setters, 
    public Role getMemberRole() {
        return memberRole;
    }

    public void setMemberRole(Role memberRole) {
        this.memberRole = memberRole;
    }

    public long getGroupId() {
        return groupId;
    }

    public long getUserId() {
        return userId;
    }

    public User getUser() {
        return user;
    }

    public Group getGroup() {
        return group;
    }
    
}
